<?

class response
{
	protected static $body;
	protected static $headers = array();
	protected static $type = null;

	public static function set_body( $body )
	{
		self::$body = $body;
	}
	
	public static function set_type( $type )
	{
		self::$type = $type;
	}

	public static function set_header( $name, $value )
	{
		self::$headers[$name] = $value;
	}

	public static function send()
	{
		if ( self::$type ) self::set_header ('Content-Type', self::$type);
		
		array_walk(self::$headers, 'response::send_header');
		echo self::$body;
	}

	public static function send_header( $value, $name )
	{
		header("$name: $value");
	}

	public static function redirect( $url )
	{
		if ( $_SERVER['HTTP_X_REQUESTED_WITH'] )
		{
			self::send_header($url, 'X-REDIRECT');
		}
		else
			self::send_header($url, 'Location');
		
		exit;
	}
}